<?php


namespace app\api\controller;


use app\common\controller\Api;
use app\common\model\Award;
use app\common\model\Meeting;
use app\common\model\Monograph;
use app\common\model\Paper;
use app\common\model\Patent;
use app\common\model\Project;
use app\common\model\Standard;
use app\common\model\Work;
use app\common\model\Talent;
use app\common\model\Science;

/**
 * 数据统计
 */
class Statistics extends Api
{
    /**
     * 列表
     *
     * @param string $start_time 开始时间
     * @param string $end_time 结束时间
     * @param int $type 类型:1=全部,其他=小类
     */
    public function list()
    {
        $start_time = input('start_time');
        $end_time = input('end_time');
        if (!$start_time) {
            $start_time = '2024-07-21';
        }
        if (!$end_time) {
            $end_time = '2099-07-21';
        }

        $type = input('type');
        if ($type != 1) {
            $where_sql['top'] = 1;
        }
        $where_sql['user_id'] = $this->auth->id;
        $where_sql['status'] = 1;
        $where_sql['create_time'] = ['between time', [$start_time, $end_time]];

        $data['project'] = Project::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['award'] = Award::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['paper'] = Paper::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['patent'] = Patent::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['work'] = Work::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['meeting'] = Meeting::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['monograph'] = Monograph::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['standard'] = Standard::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['science'] = Science::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();
        $data['talent'] = Talent::where($where_sql)->order(['top'=>'desc', 'id'=>'desc'])->select();

        $this->success('', $data);
    }
}